# coding=utf-8
# @Author: back
# @Time: 2024/10/9 8:30
import sys

from PySide6.QtCore import QSize, Qt
from PySide6.QtGui import QFont, QIcon
from PySide6.QtWidgets import (QApplication, QFrame, QGridLayout, QHBoxLayout,
                               QLabel, QLineEdit, QMainWindow, QMenuBar,
                               QPushButton, QSizePolicy, QStackedWidget, QVBoxLayout,
                               QWidget, QToolButton)
from icon.icons import *


class UiMainWindow(QMainWindow):
    # def __init__(self):
    #     super().__init__()
    #     self.setup_ui()

    def setup_ui(self, mainwin):
        mainwin.resize(800, 600)
        self.mainwidget = QWidget(mainwin)
        self.mainwidget.resize(800, 600)
        self.mainwidget.setStyleSheet(u"background-color: rgb(34, 122, 255);")
        self.gridlayout = QGridLayout(self.mainwidget)
        self.gridlayout.setContentsMargins(0, 0, 0, 0)

        self.frame_1 = QFrame(self.mainwidget)
        self.frame_1.setMaximumSize(QSize(360, 320))
        self.gridlayout.addWidget(self.frame_1)
        self.v_layout1 = QVBoxLayout(self.frame_1)

        self.stackedwidget = QStackedWidget(self.frame_1)
        self.stackedwidget.setContentsMargins(0, 0, 0, 0)
        self.stackedwidget.setMinimumSize(QSize(350, 310))
        self.stackedwidget.setStyleSheet("background-color: rgb(80, 170, 255);\n"
                                         "border-radius:20px;")
        self.v_layout1.addWidget(self.stackedwidget)

        self.stackedpage1 = QWidget(self.stackedwidget)
        self.stackedpage1.resize(340, 300)
        self.v_layout2 = QVBoxLayout(self.stackedpage1)
        self.v_layout2.setContentsMargins(9, 9, 9, 9)

        self.frame_2 = QFrame(self.stackedpage1)
        self.frame_2.setMaximumSize(QSize(282, 40))
        self.frame_2.resize(282, 40)
        self.frame_2.setStyleSheet("border-radius:30px;")
        self.v_layout2.addWidget(self.frame_2, 0, Qt.AlignmentFlag.AlignHCenter)
        self.v_layout3 = QVBoxLayout(self.frame_2)

        self.label1 = QLabel(self.frame_2)
        self.label1.setText("用户登录")
        font1 = QFont()
        font1.setPointSize(14)
        self.label1.setFont(font1)
        self.v_layout3.addWidget(self.label1)

        self.frame_3 = QFrame(self.stackedpage1)
        self.frame_3.setMinimumSize(QSize(300, 45))
        self.frame_3.resize(300, 45)
        self.h_layout1 = QHBoxLayout(self.frame_3)
        self.v_layout2.addWidget(self.frame_3, 0, Qt.AlignmentFlag.AlignHCenter)

        self.lineEdit1 = QLineEdit(self.frame_3)
        self.lineEdit1.setMinimumSize(QSize(215, 0))
        self.lineEdit1.setPlaceholderText("请输入账号")
        font2 = QFont()
        font2.setPointSize(12)
        self.lineEdit1.setFont(font2)
        self.lineEdit1.setStyleSheet(u"QLineEdit{background-color: rgb(255, 255, 255);color: rgb(0, 0, 0);}\n"
                                     "QLineEdit: focus {background-color: rgb(255, 255, 255);\n"
                                     "border:2px solid rgb(0, 0, 0);border-radius:3px;}")
        self.btn1 = QPushButton(self.frame_3)
        # btn1.setText("用户")
        self.btn1.setIcon(QIcon(":/users/user.png"))
        self.btn1.setIconSize(QSize(24, 24))
        self.h_layout1.addWidget(self.lineEdit1)
        self.h_layout1.addWidget(self.btn1)

        self.frame_4 = QFrame(self.stackedpage1)
        self.frame_4.setMinimumSize(300, 45)
        self.frame_4.resize(300, 45)
        self.h_layout2 = QHBoxLayout(self.frame_4)
        self.v_layout2.addWidget(self.frame_4, 0, Qt.AlignmentFlag.AlignHCenter)

        self.lineEdit2 = QLineEdit(self.frame_4)
        self.lineEdit2.setMinimumSize(QSize(215, 0))
        self.lineEdit2.setPlaceholderText("请输入密码")

        self.lineEdit2.setFont(font2)
        self.lineEdit2.setStyleSheet(u"QLineEdit{background-color: rgb(255, 255, 255);color: rgb(0, 0, 0);}\n"
                                     "QLineEdit: focus {background-color: rgb(255, 255, 255);\n"
                                     "border:2px solid rgb(0, 0, 0);border-radius:3px;}")

        self.btn2 = QPushButton(self.frame_4)
        # btn2.setText("密码")
        self.btn2.setIcon(QIcon(":/pwd/mima-suo.png"))
        self.btn2.setIconSize(QSize(24, 24))
        self.h_layout2.addWidget(self.lineEdit2)
        self.h_layout2.addWidget(self.btn2)

        self.frame_5 = QFrame(self.stackedpage1)
        self.frame_5.setMinimumSize(0, 140)
        self.frame_5.resize(300, 140)
        self.gridlayout2 = QGridLayout(self.frame_5)
        self.v_layout2.addWidget(self.frame_5, 0, Qt.AlignmentFlag.AlignHCenter)

        self.login1 = QToolButton(self.frame_5)
        self.login1.setText("登录")
        self.login1.setMinimumSize(QSize(75, 0))
        font3 = QFont()
        font3.setPointSize(12)
        self.login1.setFont(font3)
        self.login1.setStyleSheet(u"background-color: rgb(255, 255, 255);\n"
                                  "border-color: rgb(0, 0, 0);\n"
                                  "border:2px solid rgb(0, 0, 0);\n"
                                  "border-radius:5px;")

        self.gridlayout2.addWidget(self.login1, 0, 1)

        self.login2 = QToolButton(self.frame_5)
        self.login2.setText("登录")
        self.login2.setMinimumSize(100, 20)
        font4 = QFont()
        font4.setPointSize(11)
        self.login2.setFont(font4)
        self.login2.setStyleSheet(u"background-color: rgb(255, 255, 255);border-color: rgb(0, 0, 0);\n"
                                  "border:2px solid rgb(0, 0, 0);border-radius:5px;")
        self.gridlayout2.addWidget(self.login2, 2, 0)

        self.reg2 = QToolButton(self.frame_5)
        self.reg2.setText("注册")
        self.reg2.setMinimumSize(100, 20)
        self.reg2.toggle()
        self.reg2.setFont(font4)
        self.reg2.setStyleSheet(u"background-color: rgb(255, 255, 255);border-color: rgb(0, 0, 0);\n"
                                "border:2px solid rgb(0, 0, 0);border-radius:5px;")
        self.gridlayout2.addWidget(self.reg2, 2, 5, 1, 1)

        # line = QFrame(frame_5)
        # line.setFrameShape(QFrame.Shape.VLine)
        # line.setFrameShadow(QFrame.Shadow.Sunken)
        #
        # gridlayout2.addWidget(line, 2, 1, 1, 1)

        self.exiting = QToolButton(self.stackedpage1)
        self.exiting.setText("退出")
        self.exiting.setFont(font4)
        self.exiting.setMinimumSize(300, 20)
        self.exiting.setStyleSheet(u"background-color: rgb(255, 255, 255);border-color: rgb(0, 0, 0);\n"
                                   "border:2px solid rgb(0, 0, 0);border-radius:5px;")
        self.v_layout2.addWidget(self.exiting, 0, Qt.AlignmentFlag.AlignHCenter)
        self.exiting.clicked.connect(self.close)

        # 堆叠布局第二页↓//////////////////
        # 堆叠布局第二页↓//////////////////
        # 堆叠布局第二页↓//////////////////

        self.stackedpage2 = QWidget(self.stackedwidget)
        self.stackedpage2.resize(340, 300)
        self.v_layout4 = QVBoxLayout(self.stackedpage2)
        self.v_layout4.setContentsMargins(9, 9, 9, 9)

        self.frame_6 = QFrame(self.stackedpage2)
        self.frame_6.setMaximumSize(QSize(282, 40))
        self.frame_6.resize(282, 40)
        self.frame_6.setStyleSheet("border-radius:30px;")
        self.v_layout4.addWidget(self.frame_6, 0, Qt.AlignmentFlag.AlignHCenter)
        self.v_layout_table = QVBoxLayout(self.frame_6)

        self.label2 = QLabel(self.frame_6)
        self.label2.setText("用户注册")
        self.label2.setFont(font1)
        self.v_layout_table.addWidget(self.label2)

        self.frame_7 = QFrame(self.stackedpage2)
        self.frame_7.setMinimumSize(QSize(300, 45))
        self.frame_7.resize(300, 45)
        self.h_layout3 = QHBoxLayout(self.frame_7)
        self.v_layout4.addWidget(self.frame_7, 0, Qt.AlignmentFlag.AlignHCenter)

        self.lineEdit3 = QLineEdit(self.frame_7)
        self.lineEdit3.setMinimumSize(QSize(215, 0))
        self.lineEdit3.setPlaceholderText("请输入账号")
        self.lineEdit3.setFont(font2)
        self.lineEdit3.setStyleSheet(u"QLineEdit{background-color: rgb(255, 255, 255);color: rgb(0, 0, 0);}\n"
                                     "QLineEdit: focus {background-color: rgb(255, 255, 255);\n"
                                     "border:2px solid rgb(0, 0, 0);border-radius:3px;}")

        self.btn3 = QPushButton(self.frame_7)
        # btn1.setText("用户")
        self.btn3.setIcon(QIcon(":/users/user.png"))
        self.btn3.setIconSize(QSize(24, 24))
        self.h_layout3.addWidget(self.lineEdit3)
        self.h_layout3.addWidget(self.btn3)

        self.frame_8 = QFrame(self.stackedpage2)
        self.frame_8.setMinimumSize(300, 45)
        self.frame_8.resize(300, 45)
        self.h_layout4 = QHBoxLayout(self.frame_8)
        self.v_layout4.addWidget(self.frame_8, 0, Qt.AlignmentFlag.AlignHCenter)

        self.lineEdit4 = QLineEdit(self.frame_8)
        self.lineEdit4.setMinimumSize(QSize(215, 0))
        self.lineEdit4.setPlaceholderText("请输入密码")

        self.lineEdit4.setFont(font2)
        self.lineEdit4.setStyleSheet(u"QLineEdit{background-color: rgb(255, 255, 255);color: rgb(0, 0, 0);}\n"
                                     "QLineEdit: focus {background-color: rgb(255, 255, 255);\n"
                                     "border:2px solid rgb(0, 0, 0);border-radius:3px;}")

        self.btn4 = QPushButton(self.frame_8)
        # btn2.setText("密码")
        self.btn4.setIcon(QIcon(":/pwd/mima-suo.png"))
        self.btn4.setIconSize(QSize(24, 24))
        self.h_layout4.addWidget(self.lineEdit4)
        self.h_layout4.addWidget(self.btn4)

        self.frame_9 = QFrame(self.stackedpage2)
        self.frame_9.setMinimumSize(0, 140)
        self.frame_9.resize(300, 140)
        self.gridlayout3 = QGridLayout(self.frame_9)
        self.v_layout4.addWidget(self.frame_9, 0, Qt.AlignmentFlag.AlignHCenter)

        self.reg1 = QToolButton(self.frame_9)
        self.reg1.setText("完成注册")
        self.reg1.setMinimumSize(QSize(75, 0))
        self.reg1.setFont(font3)
        self.reg1.setStyleSheet(u"background-color: rgb(255, 255, 255);\n"
                                "border-color: rgb(0, 0, 0);\n"
                                "border:2px solid rgb(0, 0, 0);\n"
                                "border-radius:5px;")

        self.gridlayout3.addWidget(self.reg1, 0, 0, Qt.AlignmentFlag.AlignHCenter)

        self.login3 = QToolButton(self.frame_9)
        self.login3.setText("登录")
        self.login3.setMinimumSize(100, 20)
        self.login3.setFont(font3)
        self.login3.setStyleSheet(u"background-color: rgb(255, 255, 255);border-color: rgb(0, 0, 0);\n"
                                  "border:2px solid rgb(0, 0, 0);border-radius:5px;")
        self.gridlayout3.addWidget(self.login3, 2, 0, Qt.AlignmentFlag.AlignHCenter)

        # # line = QFrame(frame_9)
        # # line.setFrameShape(QFrame.Shape.VLine)
        # # line.setFrameShadow(QFrame.Shadow.Sunken)
        # #
        # # gridlayout2.addWidget(line, 2, 1, 1, 1)

        self.exiting1 = QToolButton(self.stackedpage2)
        self.exiting1.setText("退出")
        self.exiting1.setFont(font4)
        self.exiting1.setMinimumSize(300, 20)
        self.exiting1.setStyleSheet(u"background-color: rgb(255, 255, 255);border-color: rgb(0, 0, 0);\n"
                                    "border:2px solid rgb(0, 0, 0);border-radius:5px;")
        self.v_layout4.addWidget(self.exiting1, 0, Qt.AlignmentFlag.AlignHCenter)
        self.exiting1.clicked.connect(self.close)

        self.stackedwidget.addWidget(self.stackedpage1)
        self.stackedwidget.addWidget(self.stackedpage2)
        # self.stackedwidget.addWidget(self.stackedpage2)

        self.login3.clicked.connect(self.stack_index)
        self.reg2.clicked.connect(self.stack_index2)

    def stack_index(self):
        self.stackedwidget.setCurrentIndex(0)

    def stack_index2(self):
        self.stackedwidget.setCurrentIndex(1)


if __name__ == '__main__':
    app = QApplication()
    window = UiMainWindow()
    window.show()
    sys.exit(app.exec())
